package com.ruoyi.web.core.config;

import cn.hutool.system.SystemUtil;
import com.ruoyi.common.utils.biz.BizModule;
import com.ruoyi.common.utils.biz.PathUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import plugins.ConfigNative;
import java.nio.file.Path;
import java.nio.file.Paths;

@Component
@Slf4j
public class GpsInvertLibraryConfig implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        if (SystemUtil.getOsInfo().isLinux()){
            loadLib();
            setConfig();
            log.info("GPS反演所需的依赖和配置 载入完毕");
        }else {
            log.info("检测到当前非Linux环境，所以不载入so共享库");
        }

    }

    public void loadLib() {
        //System.out.println(System.getProperty("java.library.path"));
        System.loadLibrary("CommonJni");
        System.loadLibrary("TimeSpaceTransformJni");
        System.loadLibrary("LaunchPredictionJni");
        System.loadLibrary("AccessJni");
        System.loadLibrary("OrbitPredictionJni");
        System.loadLibrary("CalcSensorDataJni");
        System.loadLibrary("OrbitWizardJni");
        System.loadLibrary("CoverageAnalysisJni");
        System.loadLibrary("OrbitControlJni");
        System.loadLibrary("CoverageAnalysisJni");
        System.loadLibrary("CalcAttitudeJni");
        System.loadLibrary("HistoryOrbitAnalysisJni");
        System.loadLibrary("CloseApproachJni");
        System.loadLibrary("ManeuverJni");
        System.loadLibrary("AvodCaculateJni");
        System.loadLibrary("ConstellationJni");
        System.loadLibrary("OrbitBasicCalcJni");
        System.loadLibrary("AvoidCaculateEffectJni");
        System.loadLibrary("DataAccuracyJni");
        System.loadLibrary("LowAtmosphereCalcJni");

//        String soDirPath =  PathUtil.codeModuleDir(BizModule.DENSITY_INVERT)
//                + PathUtil.moduleDirs().getDensityInvert().get("so_dir_path")
//                + "/lib/";
//
//        System.load(soDirPath+ "libCommonJni.so");
//        System.load(soDirPath+ "libTimeSpaceTransformJni.so");
//        System.load(soDirPath+ "libLaunchPredictionJni.so");
//        System.load(soDirPath+ "libAccessJni.so");
//        System.load(soDirPath+ "libOrbitPredictionJni.so");
//        System.load(soDirPath+ "libCalcSensorDataJni.so");
//        System.load(soDirPath+ "libOrbitWizardJni.so");
//        System.load(soDirPath+ "libCoverageAnalysisJni.so");
//        System.load(soDirPath+ "libOrbitControlJni.so");
//        System.load(soDirPath+ "libCoverageAnalysisJni.so");
//        System.load(soDirPath+ "libCalcAttitudeJni.so");
//        System.load(soDirPath+ "libHistoryOrbitAnalysisJni.so");
//        System.load(soDirPath+ "libCloseApproachJni.so");
//        System.load(soDirPath+ "libManeuverJni.so");
//        System.load(soDirPath+ "libAvodCaculateJni.so");
//        System.load(soDirPath+ "libConstellationJni.so");
//        System.load(soDirPath+ "libOrbitBasicCalcJni.so");
//        System.load(soDirPath+ "libAvoidCaculateEffectJni.so");
//        System.load(soDirPath+ "libDataAccuracyJni.so");
//        System.load(soDirPath+ "libLowAtmosphereCalcJni.so");

    }
    public void setConfig()
    {
        String moduleDir = PathUtil.codeModuleDir(BizModule.DENSITY_INVERT);
        String strTrunkPath = moduleDir  + PathUtil.moduleDirs().getDensityInvert().get("trunk_path");
        ConfigNative.setEopfilePath(strTrunkPath + "/data/ADP/EOP-All.txt");
        ConfigNative.setResourceFileDir(moduleDir + "/ADP/");
//        ConfigNative.set3rdpartyDir(strTrunkPath + "/3rdparty/lib/"); //chomod +x
//        ConfigNative.setHpodDir(Paths.get(strTrunkPath).getParent()  + "/3rdparty/podsrc");//定轨程序所在目录，chomod +x

        ConfigNative.set3rdpartyDir(strTrunkPath + "/../3rdparty/lib/"); //chomod +x
        ConfigNative.setHpodDir(strTrunkPath + "/../3rdparty/podsrc");//定轨程序所在目录，chomod +x

        String soDirPath =  PathUtil.codeModuleDir(BizModule.DENSITY_INVERT) + PathUtil.moduleDirs().getDensityInvert().get("so_dir_path");
        ConfigNative.setExeFileDir(soDirPath + "/bin");//这个目录需要根据运行环境修改 就是 release_centos7/bin

    }



}
